import axios from 'axios'
import { Connect } from './tools'
var baseURL = Connect.newbaseURL
let qs = require('qs')
axios.defaults.withCredentials = true
// 测试环境用来看请求的结果
let showResult = re => {
	// console.log(re)
}
//token测试
//=============================================================普通form表单携带Token提交👇==================================================//
// form提交
let formTokenPost = axios.create({
	baseURL,
	headers: {
		'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
	},
	method: 'post',
})

formTokenPost.interceptors.request.use(config => {
	if (sessionStorage.getItem('accessToken')) {
		config.headers.Authorization = sessionStorage.getItem('accessToken')
	} else {
		_this.$message.error('网络出错，请重新登录')
		_this.$router.push('/')
	}
	return config
})
let tokenPost = (link, setting) => {
	let s = qs.stringify(setting)
	showResult(s)
	return formTokenPost.post(link, s)
}
//----------------------------------------------------------------------------------------//
let formTokenGet = axios.create({
	baseURL,
	headers: {
		'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
	},
	method: 'get',
})

formTokenGet.interceptors.request.use(config => {
	if (sessionStorage.getItem('accessToken')) {
		config.headers.Authorization = sessionStorage.getItem('accessToken')
	} else {
		_this.$message.error('网络出错，请重新登录')
		_this.$router.push('/')
	}
	return config
})
let tokenGet = (link, setting) => {
	let s = qs.stringify(setting)
	showResult(s)
	return formTokenGet.get(link, s)
}
//=============================================================JSON字符串提交👇==================================================//
// json格式
let jToken = axios.create({
	baseURL,
	headers: {
		'Content-Type': 'application/json;charset=UTF-8',
	},
	method: 'post',
})

// 请求拦截 塞入Token
jToken.interceptors.request.use(config => {
	if (sessionStorage.getItem('accessToken')) {
		config.headers.Authorization = sessionStorage.getItem('accessToken')
	} else {
		_this.$message.error('网络出错，请重新登录')
		_this.$router.push('/')
	}
	return config
})

jToken.interceptors.response.use(
	function (response) {
		let re = response.data
		showResult(re)
		return re
	},
	function (error) {
		// alert('您的网络可能有问题,请退出游戏检查网络')
		// return false
	},
)

let jtpost = (link, setting) => {
	showResult(setting)
	return jToken.post(link, setting)
}
//=============================================================Get请求携带Token获取数据👇==================================================//
// form提交
let GetToken = axios.create({
	baseURL,
	headers: {
		'Content-Type': 'application/json;charset=UTF-8',
	},
	method: 'get',
})

// 请求拦截 塞入Token
GetToken.interceptors.request.use(config => {
	if (sessionStorage.getItem('accessToken')) {
		config.headers.Authorization = sessionStorage.getItem('accessToken')
	} else {
		_this.$message.error('网络出错，请重新登录')
		_this.$router.push('/')
	}
	return config
})

GetToken.interceptors.response.use(
	function (response) {
		let re = response.data
		showResult(re)
		return re
	},
	function (error) {
		// alert('您的网络可能有问题,请退出游戏检查网络')
		// return false
	},
)

let gtpost = (link, setting) => {
	let s = qs.stringify(setting)

	showResult(s)
	return GetToken.get(link, s)
}

//=============================================================Get请求携带Token获取数据👆==================================================/
// ============================================================Delete请求👇===============================================================//
let DeleteToken = axios.create({
	baseURL,
	headers: {
		'Content-Type': 'application/json;charset=UTF-8',
	},
	method: 'delete',
})
DeleteToken.interceptors.request.use(config => {
	if (sessionStorage.getItem('accessToken')) {
		config.headers.Authorization = sessionStorage.getItem('accessToken')
	} else {
		_this.$message.error('网络出错，请重新登录')
		_this.$router.push('/')
	}
	return config
})
DeleteToken.interceptors.response.use(
	function (response) {
		let re = response.data
		showResult(re)
		return re
	},
	function (error) {
		// alert('您的网络可能有问题,请退出游戏检查网络')
		// return false
	},
)
let delaxios = (link, setting) => {
	let s = qs.stringify(setting)

	showResult(s)
	return DeleteToken.delete(link, s)
}
// ============================================================Delete请求👆===============================================================//

let TokenUrl = {
	huiyuantixian: baseURL + 'addressWithdrawList', //会员提现地址列表
	virtualwalletList: baseURL + 'virtualwalletList', //会员虚拟币列表


	userInfo: baseURL + '/huiyuanliebiao', //用户列表
	userStart:baseURL + '/forbidden', //用户启用
	reseatPwd:baseURL + '/resetpassword', //重置密码
	beauditedList:baseURL + 'bg/rengourecords', //待审核认购记录
	beauditedReview:baseURL+'/battery',//审核认购记录
	shifangList:baseURL+'bg/rewardLog',//释放记录
	transferList:baseURL+'/transferrecords/',//转账记录
	memassetslist:baseURL+'/gfc-fvirtualwallets/',//会员资产记录
	subscriptionInfomation:baseURL+'/rengous',//认购信息
	addSub:baseURL+'/rengous',//认购信息
	deleteSub:baseURL+'/rengous/',//认购信息
    jiohuoList:baseURL+'/getActiveJson',//认购信息
    manageEdit:baseURL+'arrival-level-settings/',//管理奖设置
    speedEdit:baseURL+'/admin-award-settings/',//加速奖设置
    getcusMessage:baseURL+'/reminders/',//获取客服消息
	getBType:baseURL+'/introl/dddType/',//获取币种
	getGuangGao:baseURL+'/introl/selectCoinTypeOrder/',//获取币种


	userInfoType: baseURL + 'user/userAccountManagement', //用户操作
	userInfoShenhe: baseURL + 'user/userAccountExamine', //审核
	shengcheng: baseURL + 'getPackingCode', //生成包装码
	shengchengsym: baseURL + 'createSourceCode', //生成溯源码
	shengchengjlm: baseURL + 'createRecordCode', //生成奖励码
	huiyuanliebiao: baseURL + 'huiyuanliebiao',//会员操作日志列表查询
	getClassification: '/item-cats/getJsonTree/', //获取分类
	getParentTree: '/item-cats/getParentTree', //获取父节点

	currentChange: '/item-cats/', //currentChange

	getSCS: 'bg/gfc-ent-infos', //获取生产商
}
export { tokenPost, jtpost, gtpost, TokenUrl, tokenGet, delaxios }
